public class DuoTaiDemo20 {
    public static void main(String[] args) {
        Son son = new Son("小王");
        // 多态----父类引用指向子类对象
        Father father = new Son("小王");
        father.eat();

        // 在编译阶段用的都是父亲相关的东西
        //  在运行阶段，用的时候子类的

        // 向上转型  子转父
        // 向下转型  父转子

        Father father1 = new Son1("小张");

        Son son2 = new Son("小李");

        // 运行的时候father1是Son1的对象，你把Son1对象强制转成Son对象
//        son2 = (Son) father1;
        if(father1 instanceof Son){
            Son son3 = (Son) father1;
        }
    }
}


class Father {
    private String name;

    public Father(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void eat() {
        System.out.println("吃面条");
    }
}

class Son extends Father {


    public Son(String name) {
        super(name);
    }

    @Override
    public void eat() {
        System.out.println("吃面包");
    }

    public void music() {
        System.out.println("听音乐");
    }
}

class Son1 extends Father {
    public Son1(String name) {
        super(name);
    }
}
